"""
工作流日志数据模型
"""
from datetime import datetime, timezone
from zoneinfo import ZoneInfo
from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey
from database import Base


class WorkflowLog(Base):
    """工作流日志表"""
    __tablename__ = "workflow_logs"

    id = Column(Integer, primary_key=True, index=True, autoincrement=True)
    workflow_instance_id = Column(Integer, ForeignKey("workflow_instances.id"), nullable=False, index=True)
    node_execution_id = Column(Integer, ForeignKey("workflow_node_executions.id"), nullable=True, index=True)
    log_level = Column(String(20), nullable=False, index=True)  # INFO/WARN/ERROR
    log_message = Column(Text, nullable=False)
    log_time = Column(DateTime(timezone=True), nullable=False, default=lambda: datetime.now(ZoneInfo("Asia/Shanghai")))

    def __repr__(self):
        return f"<WorkflowLog(id={self.id}, level='{self.log_level}', time='{self.log_time}')>"
